package com.theeviljames.coursework.receiver;

public class Sample implements Comparable<Sample>{

	private int sampleNo;
	private String sample;
	
	public Sample(int sampleNo, String sample) {
		this.sampleNo = sampleNo;
		this.sample = sample;
	}
	
	public int compareTo(Sample arg0) {
		if(this.sampleNo<arg0.sampleNo)return 1;
		if(this.sampleNo>arg0.sampleNo)return -1;
		return 0;
	}

	@Override
	public boolean equals(Object arg0) {
		return ((Sample)arg0).sampleNo==this.sampleNo;
	}
	
	public static Sample parseSample(String sampleString){
		//messages.put(303, "303 RETRANSMIT #");
		int a = sampleString.indexOf("#");
		int b = sampleString.substring(a+1).indexOf("#");
		String sampleNoString = sampleString.substring(a+1, b);
		int sampleNo = Integer.parseInt(sampleNoString);
		return new Sample(sampleNo, sampleString.substring(b+1));
	}
	public String toString() {
		return sampleNo + "#" + sample;
	}
}
